﻿<AvalonDock:DockableContent x:Class="ApplicationUI.ExplorerTree"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:AvalonDock="clr-namespace:AvalonDock;assembly=AvalonDock" Height="300" Width="300"
    xmlns:Commands="clr-namespace:WtfManager.UIManager;assembly=WtfManager.UIManager"
    xmlns:FileManager="clr-namespace:WtfManager.FileManager;assembly=WtfManager.FileManager"
    xmlns:HierarchicalData="clr-namespace:WtfManager.HierarchicalData;assembly=WtfManager.HierarchicalDataManager"
    xmlns:Controls="clr-namespace:WtfManager.Controls;assembly=WtfManager.Controls"
    xmlns:Commands1="clr-namespace:WtfManager.UIManager.Commands;assembly=WtfManager.UIManager"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    Title="Explorer">
  <AvalonDock:DockableContent.Resources>

    <Commands:CollectionViewSettings x:Key="viewSettings">

      <Commands:CollectionViewSettings.SortDescriptionCollection>
        <ComponentModel:SortDescription PropertyName="Name" Direction="Ascending" />
      </Commands:CollectionViewSettings.SortDescriptionCollection>

      <Commands:CollectionViewSettings.Filters>

        <FileManager:GenericFileSystemItemFilter PropertyName="IsHidden">
          <FileManager:GenericFileSystemItemFilter.Value>
            <System:Boolean>false</System:Boolean>
          </FileManager:GenericFileSystemItemFilter.Value>
        </FileManager:GenericFileSystemItemFilter>

        <FileManager:GenericFileSystemItemFilter PropertyName="IsFile">
          <FileManager:GenericFileSystemItemFilter.Value>
            <System:Boolean>false</System:Boolean>
          </FileManager:GenericFileSystemItemFilter.Value>
        </FileManager:GenericFileSystemItemFilter>

      </Commands:CollectionViewSettings.Filters>

    </Commands:CollectionViewSettings>

    <HierarchicalDataTemplate x:Key="GenericItemTemplate"
        DataType="{x:Type FileManager:FileSystemItem}" ItemsSource="{Binding Children, Converter={x:Static Commands:ItemsSourceToCollectionViewSourceConverter.Instance}, 
                      ConverterParameter={StaticResource viewSettings}}">
      <StackPanel Orientation="Horizontal" Margin="0,1,0,1">
        <Image
            Source="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext, Converter={x:Static HierarchicalData:TreeItemToImageConverter.Instance}}"
            Height="16" />
        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="3,0,0,0" />
      </StackPanel>
    </HierarchicalDataTemplate>

    <Commands:ServiceDataProvider x:Key="dataHierarchy"
        Service="{x:Type HierarchicalData:DataHierarchyService}" />

    <Style TargetType="{x:Type TreeViewItem}">
      <Setter Property="Commands:DragDropManager.IsDragable" Value="true" />
      <Setter Property="Commands:DragDropManager.AllowDrop" Value="true" />
    </Style>

  </AvalonDock:DockableContent.Resources>

  <TreeView Name="_treeView" ItemsSource="{Binding Source={StaticResource dataHierarchy}, Path=Hierarchy.Children, 
                    Converter={x:Static Commands:ItemsSourceToCollectionViewSourceConverter.Instance}, 
                    ConverterParameter={StaticResource viewSettings}}"
      ItemTemplate="{StaticResource GenericItemTemplate}" HierarchicalData:TreeItemSelectionManager.SelectedItemPath="{Binding Source={x:Static Controls:WtfDockingManager.CurrentDockingManager}, 
                Path=ActiveDocument.Data, 
                Converter={x:Static HierarchicalData:TreeItemToPathConverter.Instance},
                Mode=TwoWay}" Commands:DragDropManager.AllowDrag="True"
      >

    <Commands:SelectionManager.SelectionManager>
      <HierarchicalData:TreeItemSelectionManager />
    </Commands:SelectionManager.SelectionManager>

    <TreeView.CommandBindings>
      <Commands1:WtfCommandBinding Command="Commands1:WtfNavigationCommands.OpenInNewTab" />
    </TreeView.CommandBindings>
    <TreeView.ContextMenu>
      <ContextMenu Commands:MenuManager.ProvideMenuItems="True" Commands:MenuManager.SettingsFileName="ExplorerTreeContextMenu.xml" />
    </TreeView.ContextMenu>

  </TreeView>
</AvalonDock:DockableContent>
